home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / lang / p_image1.sit / LSP Source / Camera.p < prev    next >
Encoding:
Text File  |  1989-07-12  |  16.7 KB  |  637 lines

  1. unit Camera;
  2.  
  3. {Routines used by the Image program for supporting the Data Translation}
  4. {QuickCapture card and the Scion Image Capture 2.}
  5.  
  6. interface
  7.  
  8.  
  9.     uses
  10.         QuickDraw, OSIntf, PickerIntf, PrintTraps, ToolIntf, globals, Utilities, Graphics, FileUnit;
  11.  
  12.  
  13.     procedure AverageFrames;
  14.     procedure GetFrame; {From QuickCapture}
  15.     procedure StartDigitizing;
  16.     procedure StopDigitizing;
  17.     procedure SetVideoChannel;
  18.  
  19.  
  20.  
  21. implementation
  22.  
  23.     procedure CorrectShadingOfLine (PicPtr, BFPtr: ptr; width, BFMean: integer);
  24. {}
  25. {TYPE}
  26. {  lptr=^LineType;}
  27. {VAR}
  28. {  PicLine,BFLine:lptr;}
  29. {  i,value:integer;}
  30. {BEGIN}
  31. {  PicLine:=lptr(PicPtr);}
  32. {  BFLine:=lptr(BFPtr);}
  33. {  FOR i:=0 TO width-1 DO BEGIN}
  34. {    value:=PicLine^[i];}
  35. {    value:=255-value;}
  36. {    value:=(LongInt(value)*BFMean+(BFLine^[i] DIV 2)) DIV BFLine^[i];}
  37. {    IF value>254 THEN value:=254;}
  38. {    IF value<1 THEN value:=1;}
  39. {    PicLine^[i]:=255-value;}
  40. {  END;}
  41. {  }
  42.   {a0=data pointer}
  43.   {a1=blank field data pointer}
  44.   {d0=count}
  45.   {d1=pixel value}
  46.   {d2=blank field pixel value}
  47.   {d3=blank field mean}
  48.   {d4=temp}
  49.   {d5=max pixel value(245)}
  50.   {d6=min pixel value(1)}
  51.     inline
  52.         $4E56, $0000, {   link    a6,#0}
  53.         $48E7, $FEC0, {   movem.l    a0-a1/d0-d6,-(sp)}
  54.         $206E, $000C, {   move.l    12(a6),a0}
  55.         $226E, $0008, {   move.l    8(a6),a1}
  56.         $4280,       {   clr.l    d0}
  57.         $302E, $0006, {   move.w    6(a6),d0}
  58.         $362E, $0004, {   move.w    4(a6),d3}
  59.         $2A3C, $0000, $00FE, {   move.l    #254,d5}
  60.         $2C3C, $0000, $0001, {   move.l    #1,d6}
  61.         $5380,       {   subq.l    #1,d0}
  62.         $4281,       {   clr.l    d1}
  63.         $4282,       {   clr.l    d2}
  64.         $1210,       {L1    move.b    (a0),d1}
  65.         $1419,       {   move.b    (a1)+,d2}
  66.         $4601,       {   not.b    d1}
  67.         $C2C3,       {   mulu.w    d3,d1}
  68.         $2802,       {   move.l    d2,d4}
  69.         $E244,       {   asr.w    #1,d4}
  70.         $D284,       {   add.l    d4,d1}
  71.         $82C2,       {   divu.w    d2,d1}
  72.         $B245,       {   cmp.w    d5,d1}
  73.         $6F02,       {   ble.s    L2}
  74.         $3205,       {   move.w    d5,d1}
  75.         $B246,       {L2    cmp.w    d6,d1}
  76.         $6C02,       {   bge.s    L3}
  77.         $3206,       {   move.w    d6,d1}
  78.         $4601,       {L3    not.b    d1}
  79.         $10C1,       {   move.b    d1,(a0)+}
  80.         $51C8, $FFDE, {   dbra    d0,L1}
  81.         $4CDF, $037F, {   movem.l    (sp)+,a0-a1/d0-d6}
  82.         $4E5E,       {   unlk    a6}
  83.         $DEFC, $000C; {   add.w    #12,sp}
  84. {END;}
  85.  
  86.  
  87.     procedure CorrectShading;
  88.         var
  89.             i: integer;
  90.             offset: LongInt;
  91.             p1, p2: ptr;
  92.     begin
  93.         with info^ do begin
  94.                 if PicSize <> BlankFieldInfo^.PicSize then begin
  95.                         beep;
  96.                         exit(CorrectShading);
  97.                     end;
  98.                 ShowWatch;
  99.                 p1 := PicBaseAddr;
  100.                 p2 := BlankFieldInfo^.PicBaseAddr;
  101.                 for i := 1 to nLines do begin
  102.                         CorrectShadingOfLine(p1, p2, PixelsPerLine, BlankFieldMean);
  103.                         p1 := ptr(ord4(p1) + info^.BytesPerRow);
  104.                         p2 := ptr(ord4(p2) + BlankFieldInfo^.BytesPerRow);
  105.                         if i mod 96 = 0 then
  106.                             UpdatePicWindow;
  107.                     end;
  108.                 UpdatePicWindow;
  109.                 SetWTitle(wptr, 'Camera(Corrected)');
  110.             end;
  111.     end;
  112.  
  113.  
  114.     procedure GetFrame; {From QuickCapture}
  115.         var
  116.             tPort: GrafPtr;
  117.     begin
  118.         if info = NoInfo then
  119.             exit(GetFrame);
  120.         GetPort(tPort);
  121.         with info^ do begin
  122.                 if (PictureType <> Camera) or (PixelsPerLine <> 640) or (nlines <> 480) then
  123.                     exit(GetFrame);
  124.                 ControlReg^ := BitAnd($80, 255); {Start frame capture}
  125.                 while ControlReg^ < 0 do
  126.                     ;       {Wait for it to complete}
  127.                 UpdatePicWindow;
  128.             end;
  129.         SetPort(tPort);
  130.     end;
  131.  
  132.  
  133.     procedure SetReg (index, value: integer);
  134.         const
  135.             RegOffset = $f5fe0;
  136.         var
  137.             reg: ptr;
  138.     begin
  139.         reg := ptr(ScionSlotBase + RegOffset + index * 4);
  140.         reg^ := value;
  141.     end;
  142.  
  143.  
  144.     procedure ResetScion (GrabRect: rect; DisplayPoint: point);
  145.         const
  146.             ilutOffset = $f0000;
  147.             LineStartsRamOffset = $f4000;
  148.         type
  149.             LineStartsArray = packed array[0..8191] of UnsignedByte;
  150.             LineStartsType = ^LineStartsArray;
  151.         var
  152.             ScreenRowBytesx2: LongInt;
  153.             LutPtr: ptr;
  154.             LineStarts: LineStartsType;
  155.             EvenStart, OddStart: LongInt;
  156.             width, height, IndexOdd, IndexEven, index, i: integer;
  157.             hstart, vstart: integer;
  158.     begin
  159.         ScreenRowBytesx2 := ScreenRowBytes * 2;
  160.         LoadInputLookupTable(Ptr(ScionSlotBase + ilutOffset));
  161.         with GrabRect, DisplayPoint do begin
  162.                 hstart := BitAnd(left, $fffc);
  163.                 vstart := BitAnd(top, $fffe);
  164.                 width := right - left;
  165.                 height := bottom - top;
  166.                 EvenStart := LongInt(ScreenBase) + h + ScreenRowBytes * v;
  167.                 OddStart := EvenStart + ScreenRowBytes;
  168.                 IndexOdd := 0;
  169.                 IndexEven := (height div 2) * 16;
  170.             end;
  171.         LineStarts := LineStartsType(ScionSlotBase + LineStartsRamOffset);
  172.         for i := 1 to height div 2 do begin
  173.                 LineStarts^[IndexOdd] := BSR(BitAnd(OddStart, $ff000000), 24);
  174.                 LineStarts^[IndexOdd + 4] := BSR(BitAnd(OddStart, $ff0000), 16);
  175.                 LineStarts^[IndexOdd + 8] := BSR(BitAnd(OddStart, $ff00), 8);
  176.                 LineStarts^[IndexOdd + 12] := BitAnd(OddStart, $fc);
  177.                 LineStarts^[IndexEven] := BSR(BitAnd(EvenStart, $ff000000), 24);
  178.                 LineStarts^[IndexEven + 4] := BSR(BitAnd(EvenStart, $ff0000), 16);
  179.                 LineStarts^[IndexEven + 8] := BSR(BitAnd(EvenStart, $ff00), 8);
  180.                 LineStarts^[IndexEven + 12] := BitAnd(EvenStart, $fc);
  181.                 IndexOdd := IndexOdd + 16;
  182.                 IndexEven := IndexEven + 16;
  183.                 OddStart := OddStart + ScreenRowBytesx2;
  184.                 EvenStart := EvenStart + ScreenRowBytesx2;
  185.             end;
  186.         Index := height * 16;
  187.         LineStarts^[Index] := 0;
  188.         LineStarts^[Index + 4] := 0;
  189.         LineStarts^[Index + 8] := 0;
  190.         LineStarts^[Index + 12] := 1;
  191.         SetReg(1, 0);
  192.         SetReg(2, 162 - (width div 4));
  193.         SetReg(3, 0);
  194.         SetReg(4, 225 - (hstart div 4));
  195.         SetReg(5, 255 - (width div 4));
  196.         SetReg(6, 241 - (vstart div 2));
  197.         SetReg(7, 255 - (height div 2));
  198.     end;
  199.  
  200.  
  201.     procedure GetScionFrame (DisplayPoint: point);
  202.         type
  203.             IntPtr = ^integer;
  204.         var
  205.             FlagLoc: IntPtr;
  206.             StartTime: LongInt;
  207.     begin
  208.         with DisplayPoint do
  209.             FlagLoc := IntPtr(LongInt(ScreenBase) + h + ScreenRowBytes * v + 4);
  210.         FlagLoc^ := $00ff;
  211.         StartTime := TickCount;
  212.         SetReg(1, BitOr(128, VideoChannel * 4)); {Grab Enable}
  213.         while FlagLoc^ = $00ff do
  214.             if TickCount > (StartTime + 60) then begin
  215.                     SetReg(1, 0); {Stop Grabbing}
  216.                     exit(GetScionFrame)
  217.                 end;
  218.         SetReg(1, 0); {Stop Grabbing}
  219.     end;
  220.  
  221.  
  222.     function GetScreenPixel (h, v: integer): integer;
  223.         var
  224.             offset: LongInt;
  225.             p: ptr;
  226.     begin
  227.         offset := LongInt(v) * ScreenRowBytes + h;
  228.         p := ptr(ord4(ScreenBase) + offset);
  229.         GetScreenPixel := BAND(p^, 255);
  230.     end;
  231.  
  232.  
  233.     procedure DoMiniEventLoop (FullScreenMode: boolean);
  234.         var
  235.             loc: point;
  236.             event: EventRecord;
  237.     begin
  238.         FlushEvents(EveryEvent, 0);
  239.         if not FullScreenMode then begin
  240.                 ValuesMode := PixelValues;
  241.                 DrawLabels;
  242.             end;
  243.         repeat
  244.             GetMouse(loc);
  245.             LocalToGlobal(loc);
  246.             if not FullScreenMode then
  247.                 with loc do
  248.                     Show3RealValues(h, v, GetScreenPixel(h, v));
  249.         until GetNextEvent(mDownMask + KeyDownMask, Event);
  250.     end;
  251.  
  252.  
  253.     procedure CaptureUsingScion;
  254.         var
  255.             GrabRect: rect;
  256.             DisplayPoint: point;
  257.             FullScreenMode: boolean;
  258.             wwidth, wheight: integer;
  259.             tPort: GrafPtr;
  260.             SaveBackgroundColor, hstart, vstart, line: integer;
  261.             src, dst: ptr;
  262.             ignore: integer;
  263.             mloc: point;
  264.     begin
  265.         FullScreenMode := OptionKeyDown and (ScreenWidth = 640);
  266.         if FullScreenMode or (ScreenWidth > 640) then begin
  267.                 wwidth := MaxScionWidth;
  268.                 wheight := 480
  269.             end
  270.         else begin
  271.                 wwidth := 552;
  272.                 if wwidth > MaxScionWidth then
  273.                     wwidth := MaxScionWidth;
  274.                 wheight := 436;
  275.             end;
  276.         if ScionInfo <> nil then
  277.             with ScionInfo^.wrect, ScionInfo^ do
  278.                 if (wwidth <> right) or (wheight <> bottom) then begin
  279.                         changes := false;
  280.                         ignore := CloseAWindow(wptr);
  281.                     end;
  282.         if (ScionInfo <> nil) and (info^.PictureType <> ScionType) then begin
  283.                 SelectWindow(ScionInfo^.wptr);
  284.                 info := ScionInfo;
  285.             end;
  286.         if ScionInfo <> nil then
  287.             BringToFront(ScionInfo^.wptr);
  288.         with info^ do
  289.             if PictureType <> ScionType then begin
  290.                     if not NewPicWindow('Camera(Scion)', wwidth, wheight) then begin
  291.                             beep;
  292.                             exit(CaptureUsingScion)
  293.                         end;
  294.                     ScionInfo := info;
  295.                 end;
  296.         KillRoi;
  297.         with info^ do begin
  298.                 PictureType := ScionType;
  299.                 changes := true;
  300.                 SetWTitle(wptr, 'Camera(Live)');
  301.             end;
  302.         hstart := (640 - wwidth) div 2;
  303.         vstart := (480 - wheight) div 2;
  304.         SetRect(GrabRect, hstart, vstart, hstart + wwidth, vstart + wheight);
  305.         if FullScreenMode then
  306.             with DisplayPoint do begin
  307.                     h := BitAnd((640 - wwidth) div 2, $fffc);
  308.                     v := 0;
  309.                 end
  310.         else
  311.             with DisplayPoint do begin
  312.                     h := PicWindowLeft;
  313.                     v := PicWindowTop;
  314.                 end;
  315.         ResetScion(GrabRect, DisplayPoint);
  316.         if FullScreenMode then begin
  317.                 GetPort(tPort);
  318.                 SaveBackgroundColor := BackgroundColor;
  319.                 SetBackgroundColor(BlackC);
  320.                 EraseScreen;
  321.             end;
  322.         with info^ do begin
  323.                 if magnification <> 1.0 then
  324.                     Unzoom;
  325.                 SetReg(1, BitOr(128, VideoChannel * 4)); {Grab Enable}
  326.                 DoMiniEventLoop(FullScreenMode);
  327.                 SetReg(1, 0);   {Stop Grabbing}
  328.                 HideCursor;
  329.                 GetScionFrame(DisplayPoint);
  330.                 with DisplayPoint do
  331.                     src := ptr(LongInt(ScreenBase) + h + ScreenRowBytes * v);
  332.                 with SrcRect do
  333.                     dst := ptr(LongInt(PicBaseAddr) + left + BytesPerRow * top);
  334.                 for line := 1 to wheight do begin
  335.                         BlockMove(src, dst, wwidth);
  336.                         src := ptr(ord4(src) + ScreenRowBytes);
  337.                         dst := ptr(ord4(dst) + BytesPerRow);
  338.                     end;
  339.                 ShowCursor;
  340.             end;
  341.         if FullScreenMode then begin
  342.                 RestoreScreen;
  343.                 SetBackgroundColor(SaveBackgroundColor);
  344.                 SetPort(tPort);
  345.             end;
  346.         SetWTitle(info^.wptr, 'Camera');
  347.         if (BlankFieldInfo <> nil) and not OptionKeyDown then
  348.             CorrectShading;
  349.         FlushEvents(EveryEvent, 0);
  350.     end;
  351.  
  352.  
  353.     procedure StartDigitizing;
  354.         var
  355.             i: integer;
  356.     begin
  357.         if FrameGrabber = Scion then begin
  358.                 CaptureUsingScion;
  359.                 exit(StartDigitizing)
  360.             end;
  361.         if Digitizing then begin
  362.                 StopDigitizing;
  363.                 if BlankFieldInfo <> nil then
  364.                     wait(15);
  365.                 FlushEvents(EveryEvent, 0); {In case user holds key down too long}
  366.                 exit(StartDigitizing)
  367.             end;
  368.         if FrameGrabber = NoFrameGrabber then begin
  369.                 PutMessage('Digitizing Requires a Data Translation or SCION frame grabber card.', '', '');
  370.                 exit(StartDigitizing)
  371.             end;
  372.         if (CameraInfo <> nil) and (info^.PictureType <> camera) then begin
  373.                 SelectWindow(CameraInfo^.wptr);
  374.                 info := CameraInfo;
  375.             end;
  376.         with info^ do
  377.             if (PictureType <> Camera) or (PixelsPerLine <> 640) or (nlines <> 480) then
  378.                 if not NewPicWindow('Camera', 640, 480) then begin
  379.                         beep;
  380.                         exit(StartDigitizing)
  381.                     end;
  382.         KillRoi;
  383.         ResetQuickCapture;
  384.         Digitizing := true;
  385.         ContinuousHistogram := false;
  386.         SetItem(FunctionsMenuH, StartItem, 'Stop Digitizing');
  387.         with info^ do begin
  388.                 changes := true;
  389.                 SetWTitle(wptr, 'Camera(Live)');
  390.             end;
  391.     end;
  392.  
  393.  
  394.     procedure AddLineToSum (src, dst: ptr; width: LongInt);
  395. {$IFC false}
  396.         type
  397.             SumLineType = array[0..2047] of integer;
  398.             fptr = ^SumLineType;
  399.             lptr = ^LineType;
  400.         var
  401.             FrameLine: lptr;
  402.             SumLine: fptr;
  403.             i: integer;
  404.     begin
  405.         FrameLine := lptr(src);
  406.         SumLine := fptr(dst);
  407.         for i := 0 to width - 1 do
  408.             SumLine^[i] := SumLine^[i] + FrameLine^[i];
  409.     end;
  410. {$ENDC}
  411. inline
  412. {a0=data pointer}
  413. {a1=sum buffer pointer}
  414. {d0=count}
  415. {d1=pixel value}
  416. {d2=temp}
  417.     $4E56, $0000, {link    a6,#0}
  418.     $48E7, $E0C0, {movem.l    a0-a1/d0-d2,-(sp)}
  419.     $206E, $000C, {move.l    12(a6),a0}
  420.     $226E, $0008, {move.l    8(a6),a1}
  421.     $202E, $0004, {move.l    4(a6),d0}
  422.     $5380,              {subq.l    #1,d0}
  423.     $4281,              {clr.l    d1}
  424.     $4282,              {clr.l    d2}
  425.     $1218,              {L1    move.b    (a0)+,d1}
  426.     $3411,              {move.w    (a1),d2}
  427.     $D441,              {add.w      d1,d2}
  428.     $32C2,              {move.w    d2,(a1)+}
  429.     $51C8, $FFF6, {dbra    d0,L1}
  430.     $4CDF, $0307, {movem.l    (sp)+,a0-a1/d0-d2}
  431.     $4E5E,               {unlk    a6}
  432.     $DEFC, $000C; {add.w    #12,sp}
  433.  
  434.  
  435.  
  436. procedure AverageFrames;
  437.     type
  438.         IntPtr = ^integer;
  439.         SumLineType = array[0..2047] of integer;
  440.         sptr = ^SumLineType;
  441.         lptr = ^LineType;
  442.     var
  443.         AutoSelectAll: boolean;
  444.         SelectionSize, FrameBufferSize, offset: LongInt;
  445.         SumBase, src, srcbase, dst, OffscreenBase: ptr;
  446.         str1, str2: str255;
  447.         xLines, xPixelsPerLine, xPixelsPerLine2, frame, line, pixel: integer;
  448.         aline: LineType;
  449.         GrabRect: rect;
  450.         DisplayPoint: point;
  451.         hstart, vstart, wwidth, wheight, MinV, MaxV, value: integer;
  452.         j, range, FramesAveraged: integer;
  453.         SrcRowBytes, DstRowBytes, i: LongInt;
  454.         SumFrames: boolean;
  455.         iptr: IntPtr;
  456.         FrameLine: lptr;
  457.         SumLine: sptr;
  458.  
  459.     procedure Quit;
  460.     begin
  461.         if AutoSelectAll or (BlankFieldInfo <> nil) then
  462.             KillRoi
  463.         else
  464.             ShowRoi;
  465.         if digitizing then
  466.             StopDigitizing
  467.         else if BlankFieldInfo <> nil then
  468.             CorrectShading;
  469.     end;
  470.  
  471. begin
  472.     SumFrames := OptionKeyDown;
  473.     ValuesMode := CountValues;
  474.     DrawLabels;
  475.     if (info <> CameraInfo) and (info <> ScionInfo) then begin
  476.             PutMessage('You must have an active Camera window(created using Start Digitizing) ', 'in order to average frames.', '');
  477.             exit(AverageFrames)
  478.         end;
  479.     if NotRectangular or NotinBounds then
  480.         exit(AverageFrames);
  481.     ShowWatch;
  482.     AutoSelectAll := not Info^.RoiShowing;
  483.     if AutoSelectAll then
  484.         SelectAll(false);
  485.     with info^.osroiRect do
  486.         SelectionSize := (LongInt(right) - left) * (bottom - top);
  487.     FrameBufferSize := SelectionSize * 2;
  488.     if FrameBufferSize > BigBufSize then begin
  489.             NumToString(FrameBufferSize div 1024, str1);
  490.             NumToString(BigBufSize div 1024, str2);
  491.             str2 := concat(str1, 'K bytes are required, but only ', str2, 'K bytes are available.');
  492.             PutMessage('There is not enough memory to do the requested frame averaging. ', str2, '');
  493.             if AutoSelectAll or (BlankFieldInfo <> nil) then
  494.                 KillRoi
  495.             else
  496.                 ShowRoi;
  497.             exit(AverageFrames)
  498.         end;
  499.     WhatToUndo := NothingToUndo;
  500.     WhatsOnClip := Nothing;
  501.     SumBase := BigBuf;
  502.     if FrameGrabber = QuickCapture then
  503.         ResetQuickCapture
  504.     else begin
  505.             with info^.wrect do begin
  506.                     wwidth := right;
  507.                     wheight := bottom;
  508.                 end;
  509.             hstart := (640 - wwidth) div 2;
  510.             vstart := (480 - wheight) div 2;
  511.             SetRect(GrabRect, hstart, vstart, hstart + wwidth, vstart + wheight);
  512.             with DisplayPoint do begin
  513.                     h := PicWindowLeft;
  514.                     v := PicWindowTop;
  515.                 end;
  516.             ResetScion(GrabRect, DisplayPoint);
  517.         end;
  518.     with info^, info^.osroirect do begin
  519.             offset := left + LongInt(top) * BytesPerRow;
  520.             OffscreenBase := ptr(ord4(PicBaseAddr) + offset);
  521.             if FrameGrabber = QuickCapture then begin
  522.                     srcbase := OffscreenBase;
  523.                     SrcRowBytes := BytesPerRow;
  524.                 end
  525.             else
  526.                 with DisplayPoint do begin
  527.                         BringToFront(wptr);
  528.                         offset := left + h + (v + top) * ScreenRowBytes;
  529.                         srcbase := ptr(ord4(ScreenBase) + offset);
  530.                         SrcRowBytes := ScreenRowBytes;
  531.                     end;
  532.             xLines := bottom - top;
  533.             xPixelsPerLine := right - left;
  534.             xPixelsPerLine2 := xPixelsPerLine * 2;
  535.         end;
  536.     dst := SumBase;
  537.     for line := 1 to xLines do begin {zero buffer}
  538.             BlockMove(@BlankLine, dst, xPixelsPerLine2);
  539.             dst := ptr(ord4(dst) + xPixelsPerLine2);
  540.         end;
  541.     for frame := 0 to nFrames - 1 do begin
  542.             Show2Values(frame + 1, nframes);
  543.             if FrameGrabber = QuickCapture then begin
  544.                     ControlReg^ := BitAnd($80, 255); {Start frame capture}
  545.                     while ControlReg^ < 0 do
  546.                         ;       {Wait for it to complete}
  547.                 end
  548.             else
  549.                 GetScionFrame(DisplayPoint);
  550.             src := srcbase;
  551.             dst := SumBase;
  552.             for line := 1 to xLines do begin
  553.                     AddLineToSum(src, dst, xPixelsPerLine);
  554.                     src := ptr(ord4(src) + SrcRowBytes);
  555.                     dst := ptr(ord4(dst) + xPixelsPerLine2);
  556.                 end;
  557.             if FrameGrabber = QuickCapture then
  558.                 UpdateScreen(info^.roiRect);
  559.             if CommandPeriod then begin
  560.                     beep;
  561.                     exit(AverageFrames);
  562.                 end;
  563.         end;
  564.     src := SumBase;
  565.     dst := OffscreenBase;
  566.     DstRowBytes := info^.BytesPerRow;
  567.     if SumFrames then begin
  568.             MinV := 32767;
  569.             MaxV := 0;
  570.             iptr := IntPtr(src);
  571.             for i := 1 to SelectionSize do begin
  572.                     value := iptr^;
  573.                     if value > MaxV then
  574.                         MaxV := value;
  575.                     if value < MinV then
  576.                         MinV := value;
  577.                     iptr := IntPtr(ord4(iptr) + 2);
  578.                 end;
  579.             range := MaxV - MinV;
  580.             if range <> 0 then
  581.                 for line := 1 to xLines do begin
  582.                         SumLine := sptr(src);
  583.                         FrameLine := lptr(dst);
  584.                         for j := 0 to xPixelsPerLine - 1 do begin
  585.                                 value := SumLine^[j] - MinV + 1;
  586.                                 value := LongInt(value) * 254 div range;
  587.                                 FrameLine^[j] := value;
  588.                             end;
  589.                         src := ptr(ord4(src) + xPixelsPerLine2);
  590.                         dst := ptr(ord4(dst) + DstRowBytes);
  591.                     end
  592.             else
  593.                 beep;
  594.         end
  595.     else
  596.         for line := 1 to xLines do begin
  597.                 SumLine := sptr(src);
  598.                 FrameLine := lptr(dst);
  599.                 for j := 0 to xPixelsPerLine - 1 do
  600.                     FrameLine^[j] := SumLine^[j] div nFrames;
  601.                 src := ptr(ord4(src) + xPixelsPerLine2);
  602.                 dst := ptr(ord4(dst) + DstRowBytes);
  603.             end;
  604.     UpdatePicWindow;
  605.     Quit;
  606. end;
  607.  
  608.  
  609. procedure StopDigitizing;
  610. begin
  611.     if digitizing then begin
  612.             SetItem(FunctionsMenuH, StartItem, 'Start Digitizing');
  613.             Digitizing := false;
  614.             with info^ do
  615.                 if PictureType = camera then
  616.                     SetWTitle(wptr, 'Camera');
  617.             if (BlankFieldInfo <> nil) and not OptionKeyDown then
  618.                 CorrectShading;
  619.         end;
  620. end;
  621.  
  622.  
  623. procedure SetVideoChannel;
  624.     var
  625.         TempChannel: integer;
  626. begin
  627.     if FrameGrabber = Scion then begin
  628.             TempChannel := GetInt('Scion Input Channel(1..4):', VideoChannel + 1);
  629.             TempChannel := TempChannel - 1;
  630.         end
  631.     else
  632.         TempChannel := GetInt('QuickCapture Input Channel(0..3):', VideoChannel);
  633.     if (TempChannel >= 0) and (TempChannel <= 3) then
  634.         VideoChannel := TempChannel;
  635. end;
  636.  
  637. end.